//==========================================================================
// Copyright (c) 2000-2008,  Elastos, Inc.  All Rights Reserved.
//==========================================================================

#include <string.h>

int __cdecl _wcsicmp(const wchar_t * str1, const wchar_t * str2)
{
    int c1, c2;
    do {
        c1 = *str1++;
        if (c1 >= 'A' && c1 <= 'Z') // convert to lower case.
            c1 -= 'A' - 'a';

        c2 = *str2++;
        if (c2 >= 'A' && c2 <= 'Z') // convert to lower case.
            c2 -= 'A' - 'a';
    } while (c1 && (c1 == c2));
    return (c1 - c2);

/*
    register int __res;
#if !defined(_arm)
    int d0;
    asm __volatile__(
        "movl %4, %%edi\n"
        "1:\tmovl (%%esi), %%ebx\n\t"
        "cmpw $0x41, %%bx\n\t" //convert to lower case.
        "jb 2f\n\t"
        "cmpw $0x5a, %%bx\n\t"
        "ja 2f\n\t"
        "addw $0x20, %%bx\n\t"
        "2:\tmovl (%%edi), %%edx\n\t"
        "cmpw $0x41, %%dx\n\t" //convert to lower case.
        "jb 3f\n\t"
        "cmpw $0x5a, %%dx\n\t"
        "ja 3f\n\t"
        "addw $0x20, %%dx\n\t"
        "3:\tsubw %%dx, %%bx\n\t"
        "cmpw $0, %%bx\n\t"
        "jne 4f\n\t"
        "addl $2, %%edi\n\t"
        "addl $2,%%esi\n\t"
        "cmpl $0, (%%edi)\n\t"
        "jne 1b\n"
        "4:\txorl %%eax, %%eax\n\t"
        "movw %%bx, %%ax\n\t"
        :"=a"(__res), "=&S" (d0)
        :"0" (0), "1" (str1), "g" (str2)
        :"di", "dx", "bx");
#else
    asm __volatile__(
        "1:\tldrh r2, [r0], #2\n\t"
        "cmp r2, #0x41\n\t"
        "blt 2f\n\t"
        "cmp r2, #0x5a\n\t"
        "bhi 2f\n\t"
        "add r2, r2, #0x20\n"
        "2:\tldrh r3, [r1], #2\n\t"
        "cmp r3, #0x41\n\t"
        "blt 3f\n\t"
        "cmp r3, #0x5a\n\t"
        "bhi 3f\n\t"
        "add r3, r3, #0x20\n"
        "3:\tcmp r3, r2\n\t"
        "bne 4f\n\t"
        "mov r3, r3, lsl #16\n\t"
        "mov r3, r3, lsr #16\n\t"
        "cmp r3, #0\n\t"
        "bne 1b\n"
        "4:\tsub r4, r2, r3\n\t"
        "mov %0, r4\n\t"
        :"=r"(__res)
        ::"r2", "r3", "r4");
#endif

    return __res;
*/
}

int __cdecl _stricmp(const char * str1, const char * str2)
{
    int c1, c2;
    do {
        c1 = (unsigned char)*str1++;
        if (c1 >= 'A' && c1 <= 'Z') // convert to lower case.
            c1 -= 'A' - 'a';

        c2 = (unsigned char)*str2++;
        if (c2 >= 'A' && c2 <= 'Z') // convert to lower case.
            c2 -= 'A' - 'a';
    } while (c1 && (c1 == c2));
    return (c1 - c2);
/*
    register int __res;
#if !defined(_arm)
    int d0;
    asm __volatile__(
        "movl %4, %%edi\n"
        "1:\tmovl (%%esi), %%ebx\n\t"
        "cmp $0x41, %%bl\n\t" //convert to lower case.
        "jb 2f\n\t"
        "cmp $0x5a, %%bl\n\t"
        "ja 2f\n\t"
        "add $0x20, %%bl\n\t"
        "2:\tmovl (%%edi), %%edx\n\t"
        "cmp $0x41, %%dl\n\t" //convert to lower case.
        "jb 3f\n\t"
        "cmp $0x5a, %%dl\n\t"
        "ja 3f\n\t"
        "add $0x20, %%dl\n\t"
        "3:\tsub %%dl, %%bl\n\t"
        "cmp $0, %%bl\n\t"
        "jne 4f\n\t"
        "incl %%edi\n\t"
        "incl %%esi\n\t"
        "cmpl $0, (%%edi)\n\t"
        "jne 1b\n"
        "4:\txorl %%eax, %%eax\n\t"
        "mov %%bl, %%al\n\t"
        :"=a"(__res), "=&S" (d0)
        :"0" (0), "1" (str1), "g" (str2)
        :"di", "dx", "bx");
#else
    asm __volatile__(
        "1:\tldr r2, [r0], #1\n\t"
        "cmp r2, #0x41\n\t"
        "blt 2f\n\t"
        "cmp r2, #0x5a\n\t"
        "bhi 2f\n\t"
        "add r2, r2, #0x20\n"
        "2:\tldr r3, [r1], #1\n\t"
        "cmp r3, #0x41\n\t"
        "blt 3f\n\t"
        "cmp r3, #0x5a\n\t"
        "bhi 3f\n\t"
        "add r3, r3, #0x20\n"
        "3:\tcmp r3, r2\n\t"
        "bne 4f\n\t"
        "cmp r3, #0\n\t"
        "bne 1b\n"
        "4:\tsub r4, r2, r3\n\t"
        "mov %0, r4\n\t"
        :"=r"(__res)
        ::"r2", "r3", "r4");
#endif

    return __res;
*/
}
